/*
 * ClientListener.cpp
 *
 *  Created on: May 25, 2011
 *      Author: madboyka
 */

#include "ClientListener.h"
#include "ClientProtocolFactory.h"
#include "Logger.h"

ClientListener::ClientListener(Server* server)
{
	this->server = server;
}

ClientListener::~ClientListener()
{
}

void ClientListener::run()
{
	Logger::log("Client listener started...");
	protocol = ClientProtocolFactory::create("SocketTcp");
	try
	{
		protocol->initServer();
	} catch (NetworkException ex)
	{
		Logger::error(ex.showReason());
	}
	while (true)
	{
		try
		{
			ClientProtocol *p = protocol->acceptConnection();
			server->addClient(p);
		} catch (NetworkException ex)
		{
			Logger::log(ex.showReason());
		}
	}
}
